package com.sp.scmdb.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.sp.scmdb.common.DomainObject;

@Entity
@Table(name = "VIEW_REAL_DATA")
public class RealData extends DomainObject {

	/** 人员ID */
	@Column(name="empID")
	private int empID;

	/** 电子标签号 */
	@Column(name="labelID")
	private int labelID;
	
	/** 读头号 */
	@Column(name="lrmID")
	private int lrmID;
	
	/** 进入读头时间 */
	@Column(name="inTime")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime inTime;

	/** 离开读头时间 */
	@Column(name="outTime")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime outTime;

	/** 入园时间 */
	@Column(name="inWellTime")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime inWellTime;

	/** 具体班次ID */
	@Column(name="idShiftsDetails")
	private Integer idShiftsDetails;	

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "empID", insertable = false, updatable = false)
	private Employee employee;

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
	
	public int getEmpID() {
		return empID;
	}

	public void setEmpID(int empID) {
		this.empID = empID;
	}
	public DateTime getInTime() {
		return inTime;
	}

	public int getLabelID() {
		return labelID;
	}

	public void setLabelID(int labelID) {
		this.labelID = labelID;
	}

	public int getLrmID() {
		return lrmID;
	}

	public void setLrmID(int lrmID) {
		this.lrmID = lrmID;
	}

	public void setInTime(DateTime inTime) {
		this.inTime = inTime;
	}

	public DateTime getOutTime() {
		return outTime;
	}

	public void setOutTime(DateTime outTime) {
		this.outTime = outTime;
	}

	public Integer getIdShiftsDetails() {
		return idShiftsDetails;
	}

	public void setIdShiftsDetails(Integer idShiftsDetails) {
		this.idShiftsDetails = idShiftsDetails;
	}
	
	public DateTime getInWellTime() {
		return inWellTime;
	}

	public void setInWellTime(DateTime inWellTime) {
		this.inWellTime = inWellTime;
	}

	public String getInWellTimeString(){
		if (null != this.inWellTime) {
			return this.inWellTime.toString("yyyy-MM-dd HH:mm:ss");			
		}
		return null;
	}

	public void setInWellTimeString(String inTimeString){
		if (StringUtils.isNotEmpty(inTimeString)) {
			DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");			
			this.inWellTime = formatter.parseDateTime(inTimeString);
		}
	}
}
